package com.show.controller;

import com.alibaba.fastjson.JSON;
import com.show.pojo.Base;
import com.show.pojo.R;
import com.show.service.BaseService;
import com.show.service.impl.BaseServiceImpl;
import com.show.vo.CityCompanyDataVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author 绛河
 */
@WebServlet("/base/*")
public class BaseController extends BaseServlet {
    private BaseService baseService = new BaseServiceImpl();

    public void searchAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Base> bases = baseService.searchAll();
        String jsonString = JSON.toJSONString(bases);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }

    public void searchCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Integer integer = baseService.searchCount();
        String jsonString = JSON.toJSONString(integer);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }


    public void searchByGroup(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<R> rs = baseService.searchByGroup();
        String jsonString = JSON.toJSONString(rs);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }


    public void searchByNature(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Map<String, Object>> maps = baseService.searchByNature();
        String jsonString = JSON.toJSONString(maps);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }

    public void searchByIndustry(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Map<String, Object>> maps = baseService.searchByIndustry();
        String jsonString = JSON.toJSONString(maps);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }



    public void searchTop(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Map<String, Object>> maps = baseService.searchTop();
        String jsonString = JSON.toJSONString(maps);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);

    }

    public void findCityCompany(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<CityCompanyDataVo> cityCompany = baseService.findCityCompany();
        String jsonString = JSON.toJSONString(cityCompany);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }


}
